package org.example;

import java.util.Scanner;

public class Main {


    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        String s = scanner.nextLine();
        String l = scanner.nextLine();
        int count = -1;
        int i=0,j =0;
        while (i < s.length() && j<l.length()){
            if (s.charAt(i) == l.charAt(j)){
                if (i == s.length()){
                    count = j;
                }
                i++;
            }
            j++;
        }
        System.out.println(count);

    }
}
